﻿using System;
using System.Linq;
using System.Reflection;

namespace AppFrame.Binding
{
    public class AttributeHelper
    {
        public static object[] GetAttribute(Type type,object obj)
        {
            return obj.GetType().GetCustomAttributes(type, false);
        }
        public static object GetFirstAttribute(Type type, object obj)
        {
            object[] objects =  obj.GetType().GetCustomAttributes(type, false);
            if(objects.Length>0)
            {
                return objects[0];
            }
            return null;
            
        }

        public static object CreateGeneric(Type generic, Type innerType, params object[] args)
        {
            System.Type specificType = generic.MakeGenericType(new System.Type[] { innerType });
            return Activator.CreateInstance(specificType, args);
        }
    }
}
